<!DOCTYPE html>
<html lang="en" xmlns:v-on="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title></title>
    <script src="https://unpkg.com/vue"></script>
    <script>
        window.onload=function(){
            var app4=new Vue({
                el:'#app',

                methods:{
                    reverseMessage:function(){
                        this.message=this.message.split('').reverse().join('')
                    },
                    addpeople:function(){
                        var x={name:this.username,age:this.age,time:new Date()};
                        this.peoples.push(x);
                    },
                    removeall:function(){this.people=[];},
                    remove:function(index){
                    this.peoples.splice(index,1);
                    }
                },
                data:{
                    username:'',
                    age:null,
                    message:'hello vue.js!',
                    peoples:[
                        {name:'马云',age:18,time:new Date()},
                        {name:'马化腾',age:16,time:new Date()}
                    ]
                },
                filters:{
                    hhmmss:function(val){
                        return(val.getHours()+":"+val.getMinutes()+":"+val.getSeconds())
                    },
                    capitalize:function(value){
                        if(!value)return''
                        value=value.toString()
                        return value.charAt(0).toUpperCase()+value.slice(1);
                    }
                }
            });
        }
    </script>
</head>
<body>
<div id="app">
    <p>{{message}}</p>
    <input v-model="username"><br>
    <input v-model="age"><br>
    <button v-on:click="addpeople" >添加</button>
    <button v-on:click="removeall">删除</button>

    <table border="1">
        <tr> <th>序号</th>
             <th>名字</th>
             <th>年龄</th>
             <th>时间</th>
             <th>操作</th></tr>
        <tr v-for="(people,index) in peoples">
            <td>{{index+1}}</td><td>{{people.name | capitalize}}</td><td>{{people.age}}</td>
            <td>{{people.time |hhmmss}}</td>
            <td><button v-on:click="remove(index)">删除</button></td>
        </tr>
    </table>
</div>

</body>
</html>